﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Autenticacao
{
    public partial class frm_explvaci : Form
    {
        System.Data.SqlClient.SqlConnection con;

        public Exploracao ex2;
        public Medicamento md2;

        public string data;
        private string op1;

        public frm_explvaci(Exploracao ex1, Medicamento md1, string op, string data)
        {
            this.ex2 = ex1;
            this.md2 = md1;
            this.op1 = op;
            this.data = data;

            InitializeComponent();
            if (op1 == "med")
            {
                txtve_data.Text = data;
                txtve_medic.Text = md2.get_nome().ToString();
            }
            else
                txtve_data.Text = data;
        }

        private void frm_explvaci_Load(object sender, EventArgs e)
        {

        }

        private void lblnome_Click(object sender, EventArgs e)
        {

        }

        private void cmdve_id_Click(object sender, EventArgs e)
        {
            con = new System.Data.SqlClient.SqlConnection();
            con.ConnectionString = @"Data Source = ANDRÉ-PC\SQLEXPRESS; Initial Catalog = horsepw_bd; Integrated Security = True;";
            con.Open();
            
            if (txtve_data.Text == "" || txtve_data.Text == "aaaa/MM/dd" || txtve_medic.Text == "")
                MessageBox.Show("Tem de inserir uma data e um medicamento!", "Faltam dados", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            else
            {
                int ide = ex2.get_id();
                int idm = md2.get_id();
                
                SqlCommand command1 = con.CreateCommand();
                command1.CommandText = "Insert into Vacinacao_exploracao (data_administracao, id_medicamento, id_exploracao) Values ('" + txtve_data.Text + "', " + idm + ", " + ide + ")";
                command1.CommandType = CommandType.Text;
                SqlDataReader reader1 = command1.ExecuteReader();

                MessageBox.Show("Registo de Vacinação adicionado com sucesso!", "Vacinação inserida", MessageBoxButtons.OK, MessageBoxIcon.Information);

                con.Close();

                txtve_data.Text = "aaaa/MM/dd";
                txtve_medic.Text = "";
            }
        }

        private void cmdve_procurar_Click(object sender, EventArgs e)
        {
            if (txtve_data.Text == "" || txtve_data.Text == "aaaa/MM/dd")
                MessageBox.Show("Tem de inserir uma data!", "Faltam dados", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            else
            {
                data = txtve_data.Text;
                
                frm_geProcMed frm1 = new frm_geProcMed(ex2, data);
                this.Hide();
                frm1.ShowDialog();
            }
        }

        private void cmdve_voltar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cmdve_va_Click(object sender, EventArgs e)
        {
            frm_vachist frm2 = new frm_vachist(ex2);
            frm2.ShowDialog();
        }
    }
}
